package com.adjy.pathbuilders.screens;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;

import com.adjy.pathbuilders.objects.Coin;
import com.adjy.pathbuilders.objects.GameEntityType;
import com.adjy.pathbuilders.rendering.Animation;
import com.adjy.pathbuilders.rendering.AnimationPack;
import com.adjy.pathbuilders.rendering.GameCanvas;
import com.adjy.pathbuilders.rendering.loading.AnimationFactory;
import com.adjy.pathbuilders.world.GameWorld;

public class ShowdoorScreen implements GameScreen {
	
	private Paint defaultPaint;
	private AnimationFactory animationFactory;
	private GameWorld parent;
	private AnimationPack arrowPack;
	private int posXDoor;
	private int posYDoor;
	
	
	
	public ShowdoorScreen(AnimationFactory anFactory, GameWorld parent) {
		this.parent = parent;
		this.animationFactory = anFactory;
		posXDoor = 50;
		posYDoor = 50;		
		
		
	}
	
	//public void createCoin
	/**
	 * Creates the default paint, which can write simple messages in the screen.
	 */
	private void createDefaultPaint() {
		this.defaultPaint = new Paint();
		this.defaultPaint.setColor(Color.BLUE);
		this.defaultPaint.setTextSize(50);
		this.defaultPaint.setAntiAlias(true);
	}
	
	private void createDisplay() {
		plotScore();
	}

	private void plotScore() {
		this.arrowPack = this.animationFactory.getAnimationsFor(GameEntityType.ARROW); // 50, 600
	}
	
	private int getCurrentTime() {
		return (int) this.parent.getCurrentTime();
	}

	@Override
	public void render(GameCanvas canvas, float timeElapsed) {

		canvas.drawBitmapFromPhysics(this.arrowPack.getAnimation(
				GameEntityType.getDefaultAnimationName(GameEntityType.ARROW)).getCurrentFrame(timeElapsed),
				posXDoor, posYDoor);
		
		if (this.parent.getMainChar().isDrunk()){
			
			float posX = this.parent.getMainChar().getBody().getPosition().x-2;
			float posY = this.parent.getMainChar().getBody().getPosition().y+10;
			canvas.drawBitmapFromPhysics(this.animationFactory.getAnimationsFor(GameEntityType.BUBBLES).getAnimation(
					GameEntityType.getDefaultAnimationName(GameEntityType.BUBBLES)).getCurrentFrame(timeElapsed),
					posX, posY);
		}

		//plotLivesCounter(canvas);
	}
		
	private void plotLivesCounter(GameCanvas canvas) {
		canvas.drawTextWithConversion("X = "+this.parent.getMainChar().getBody().getPosition().x+" "+
				"Y = "+this.parent.getMainChar().getBody().getPosition().y+" ", 100, 100, this.defaultPaint);
	}

	@Override
	public void load() {
		createDefaultPaint();
		createDisplay();
	}

	@Override
	public void release() {
		// GameWorld should take care of unloading Animations
	}

	@Override
	public void input(MotionEvent event) {
	}

	@Override
	public void step(float timePassed) {
	}

	public int getPosXDoor() {
		return posXDoor;
	}

	public void setPosXDoor(int posXDoor) {
		this.posXDoor = posXDoor;
	}

	public int getPosYDoor() {
		return posYDoor;
	}

	public void setPosYDoor(int posYDoor) {
		this.posYDoor = posYDoor;
	}
	
}
